Cordio BLE: Fix two integer overflows (CVE-2024-48982) #386
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
hciEvtProcessMsg
parses incoming hci command packets. In doing so, it dynamically determines the length of the packet body by reading a byte from the packet header.mbed-os/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/hci/dual_chip/hci_evt.c
Line 2748 in 54e8693
Then,
hciEvtProcessCmdCmpl
is called. A buffer is allocated to hold the packet, the length of which is determined by the sum of this 8-bit integer and the length of a structure to hold some metadata but without 3 bytes that are assumed to exist and have already been read.mbed-os/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/hci/dual_chip/hci_evt.c
Lines 2685 to 2695 in 54e8693
This can be exploited in 2 ways, the first of which sets a
len < 3
. This means thatThe other takes advantage of the fact that
msgSize
is auint8_t
.Picking a
len = 0xff
leaves:This leads to a too small allocation for the message buffer and the following call to
memcpy()
results in a buffer overflow.This fix addresses both of these issues by:
msgSize
to be auint16_t
Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results